/** 
 * @jsName: FinPayinfoManaged.js 
 * @author Sean Cui
 * @date 2017-04-16 下午3:46:00 
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @version V1.0.0.0
 * @comment 该文件通过代码生成器生成，如果修改次文件后，重新生成时将覆盖修改内容，请修改生成模板或做好备份
 */

var FinPayinfoManaged = function() {
	return {
		datatable : null,
		init : function() {
			$('#payStartTime').datetimepicker({
        		lang:'ch',
        		timepicker:false,
        		format:'Y-m-d'
        	});
			$('#payEndTime').datetimepicker({
        		lang:'ch',
        		timepicker:false,
        		format:'Y-m-d'
        	});
			this.initSearch();
			this.initListener();
		},
		initSearch : function() {
			if (!jQuery().dataTable) {
				return;
			}
			var listTable = $("#FinPayinfoListTable").dataTable({
				"sAjaxSource" : ctx + "/finPayinfo/search?now=" + new Date().getTime(),
				/* 使用post方式 */
				"fnServerData" : function(sSource, aoData, fnCallback) {
					var postData = {
						page : 1,
						start : 0,
						rows : 10,
						params : {}
					};
					
					if($('#payNo').val()){
						postData.params.payNo = "%"+($('#payNo').val()).replace(/\s/g,"%")+"%";
					}
					if($('#companyName').val()){
						postData.params.companyName = "%"+($('#companyName').val()).replace(/\s/g,"%")+"%";
					}
					if($('#payAccount').val()){
						postData.params.payAccount = "%"+($('#payAccount').val()).replace(/\s/g,"%")+"%";
					}
					if($('#payWay').val()){
						postData.params.payWay = ($('#payWay').val());
					}
					if($('#payStartTime').val()){
						postData.params.payStartTime = ($('#payStartTime').val());
					}
					if($('#payEndTime').val()){
						postData.params.payEndTime = ($('#payEndTime').val());
					}

					// 参数
					for (var i = 0, size = aoData.length; i < size; i++) {
						if (aoData[i].name == 'iDisplayLength') {
							postData.rows = aoData[i].value;
						} else if (aoData[i].name == 'iDisplayStart') {
							postData.start = aoData[i].value;
						} else if (aoData[i].name == 'sEcho') {
							postData.page = aoData[i].value;
						}
					}

					$.ajax({
						"dataType" : 'json',
						"type" : "POST",
						"cache": false,
						"url" : sSource,
						"data" : postData,
						"success" : function(data, textStatus, jqXHR){
							fnCallback(data.data, textStatus, jqXHR);
						}
					});
				},
				"bAutoWidth":false,
				"aoColumnDefs" : [
						{
							"data" : "index",
							"aTargets" : [ 0 ]
						},
						{
							"data" : "payNo",
							"aTargets" : [ 1 ]
						},
						{
							"data" : "companyName",
							"aTargets" : [ 2 ]
						},
						{
							"data" : "payAccount",
							"aTargets" : [ 3 ]
						},
						{
							"data" : "payWay",
							"aTargets" : [ 4 ]
						},
						{
							"data" : "payAmount",
							"aTargets" : [ 5 ]
						},
						{
							"data" : "procedFee",
							"aTargets" : [ 6 ]
						},
						{
							"data" : "payTime",
							"aTargets" : [ 7 ]
						},
						{
							"aTargets" : [ 8 ],
							"mRender" : function(data, type, full) {
								var btns =  '';
								btns +=  Permission.createPermElement('finPayinfo:list:modify',' <button title="'+messages.public_button_edit+'" class="btn btn-sm btn-primary" name="edit" target_id="'+full.id+'"><i class="fa fa-pencil-square-o"></i></button>');
								return btns;
							}
						}
				]
			});
			this.datatable = listTable;
		},reSearch:function(){
        	this.datatable.fnDraw();
        },removeClass:function(){//去除Form表单的验证样式
        	$('.form-group','#actForm').removeClass('has-success')
            .removeClass('has-error');
    		 $('span').remove('.help-block');
        },initListener : function() {
			/*
			 * 查询
			 */
			$("#searchBtn").click(function() {
				FinPayinfoManaged.reSearch();
				return false;
			});

			/*
			 * 清除
			 */
			$("#clearBtn").click(function() {
				$("#searchForm")[0].reset();
				FinPayinfoManaged.reSearch();
				return false;
			});

			/*
			 * 查看详情
			 */
			$('#FinPayinfoListTable tbody').on('click', 'button[name="edit"]',function() {
				var id = $(this).attr("target_id");
				alert("查看详情");
			});
			
		},
		
	};

}();

/*
 * Powered By [Code-Generator]
 * Web Site: http://www.hwelltech.com
 */

